#include <stdio.h>
#include <string.h>

typedef struct Worker {
    char name[20];
    long int id;
} WK;

void sort(WK peo[10], char names[10][20]) {
    for (int i = 0; i < 9; i++) {
        for (int j = 0; j < 9 - i; j++) {
            if (peo[j].id > peo[j + 1].id) {
                WK temp = peo[j];
                peo[j] = peo[j + 1];
                peo[j + 1] = temp;
                char temp_name[20];
                strcpy(temp_name, names[j]);
                strcpy(names[j], names[j + 1]);
                strcpy(names[j + 1], temp_name);
            }
        }
    }
}
void find(WK peo[10],long int id) {
    //折半查找id
    int left = 0, right = 9, mid,flag=0;
    while (left <= right) {
        mid = (left + right) / 2;
        if (peo[mid].id == id) {
            printf("%s %ld\n", peo[mid].name, peo[mid].id);
            flag=1;
            break;
        } else if (peo[mid].id > id) {
            right = mid - 1;
        } else {
            left = mid + 1;
        }
    }
    if(flag==0)
    printf("没有该职工信息!");

}

int main() {
    WK peo[10] = {0};
    char names[10][20];
    printf("输入职工数据:\n");
    for (int i = 0; i < 10; i++) {
        scanf("%s %ld", peo[i].name, &peo[i].id);
        strcpy(names[i], peo[i].name);
    }
    printf("排序后:\n");
    sort(peo, names);
    for (int i = 0; i < 10; i++) {
        printf("%s %ld\n", peo[i].name, peo[i].id);
    }
    long int id;
    printf("输入寻找的职工号:\n");
    scanf("%ld", &id);
    find(peo, id);
    return 0;
}